package com.hssy.wululuaplan.controller;


import com.hssy.wululuaplan.common.Result;
import com.hssy.wululuaplan.form.StudentForm;
import com.hssy.wululuaplan.service.StudentService;
import com.hssy.wululuaplan.vo.StudentClassVo;
import com.hssy.wululuaplan.vo.StudentVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  学生管理 前端控制器
 * </p>
 *
 * @author Mr.Hongtao
 * @since 2024-02-27
 */
@Api(tags = "学生管理")
@RestController
@RequestMapping("/wululuaplan/student")
public class StudentController {
    @Resource
    private StudentService studentService;

    @ApiOperation("查询学生列表")
    @GetMapping("/findStudentList")
    public Result<Map<String,Object>> findStudentList() {
        Map<String,Object> map = studentService.findStudentListInitial();
        return Result.success(map);
    }

    @ApiOperation(value = "根据id或姓名查询学生",notes = "本来分开写最好，懒得处理了，注意把里面逻辑完善")
    @GetMapping("/findById")
    public Result<StudentVo> findById(@RequestParam(value = "id", required = false) Integer id,
                                      @RequestParam(value = "studentName", required = false) String studentName){
        StudentVo studentVo = studentService.findById(id, studentName);
        return Result.success(studentVo);
    }

    @ApiOperation("查询可以排课的学生列表")
    @GetMapping("/findHasRemainStudentList")
    public Result<List<StudentClassVo>> findHasRemainStudentList(@RequestParam("courseId") Integer courseId) {
        List<StudentClassVo> list = studentService.findHasRemainStudentList(courseId);
        return Result.success(list);
    }

    @ApiOperation("新增学生")
    @PostMapping("/create")
    public Result<String> create(@RequestBody StudentForm form) {
        studentService.create(form);
        return Result.success();
    }

    @ApiOperation("修改学生")
    @PostMapping("/edit")
    public Result<String> edit(@RequestBody StudentForm form) {
        studentService.edit(form);
        return Result.success();
    }

    @ApiOperation("删除学生")
    @PostMapping("/delete")
    public Result<String> delete(Integer id) {
        studentService.deleteStudent(id);
        return Result.success();
    }
}

